import React from 'react';
import Dialog from '../../../../node_modules/material-ui/lib/dialog';
import FlatButton from '../../../../node_modules/material-ui/lib/flat-button';
import RaisedButton from '../../../../node_modules/material-ui/lib/raised-button';
import HttpRequest from './../HttpRequest.js';
import dialogManager from './../dialogManager.jsx';
import Input from '../../../../node_modules/react-bootstrap/lib/Input';

/**
 * 判断用户存不存在
 * 判断用户是否已经是成员
 * 添加失败时提示
 * 不应该用userName 而是Id
 */

let EditMemberDlg = React.createClass({
    getInitialState:function(){
        return {
            open: false,
            name: "",
            role:"",
            _id:""

        }
    },
    handleCompleted:function(){
        var data= {
            _id:this.state._id,
            role:this.refs.role.getValue()
        };
        this.props.editMember(data);
        this.handleClose();
    },
    handleOpen: function(info){
        this.setState({
            name: info.name,
            role:info.role,
            _id:info._id,
            open: true
        });
    },

    handleClose: function(){
        this.setState({open: false});
    },
    render() {
        const actions = [
            <FlatButton
                label="取消"
                secondary={true}
                onTouchTap={this.handleClose}
            />,
            <FlatButton
                label="完成"
                primary={true}
                disabled={false}
                onTouchTap={this.handleCompleted}
            />
        ];
        return (
            <div>
                <Dialog
                    title="修改成员权限"
                    actions={actions}
                    modal={true}
                    open={this.state.open}
                >
                    <Input type="text" ref="userName" label="用户" placeholder="Enter text" style={{width:"300px"}} value = {this.state.name}/><p/>
                    <Input type="select" ref="role" label="角色" placeholder="Enter text" style={{width:"300px"}}>
                        <option value="admin">管理员</option>
                        <option value="developer">开发者</option>
                        <option value="observer">观察者</option>
                    </Input><p/>
                </Dialog>
            </div>
        );
    }
});
dialogManager.addDialog("edit_member_dialog",EditMemberDlg);
module.exports = EditMemberDlg;